unit pardeglist;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, Wwdbigrd, Wwdbgrid, StdCtrls, Buttons, wwSpeedButton,
  wwDBNavigator, ExtCtrls, wwclearpanel, Db, ADODB, DBGrids, ImgList;

type
  TPardeglis = class(TForm)
    wwDBGrid1: TwwDBGrid;
    st: TStaticText;
    Label1: TLabel;
    wwDBNavigator1: TwwDBNavigator;
    wwDBNavigator1First: TwwNavButton;
    wwDBNavigator1PriorPage: TwwNavButton;
    wwDBNavigator1Prior: TwwNavButton;
    wwDBNavigator1Next: TwwNavButton;
    wwDBNavigator1NextPage: TwwNavButton;
    wwDBNavigator1Last: TwwNavButton;
    bTamam: TBitBtn;
    bVazgec: TBitBtn;
    ImageList1: TImageList;
    procedure wwDBGrid1DblClick(Sender: TObject);
    procedure bTamamClick(Sender: TObject);
    procedure bVazgecClick(Sender: TObject);
    procedure wwDBGrid1RowChanged(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure wwDBGrid1CalcTitleAttributes(Sender: TObject;
      AFieldName: String; AFont: TFont; ABrush: TBrush;
      var ATitleAlignment: TAlignment);
    procedure wwDBGrid1TitleButtonClick(Sender: TObject;
      AFieldName: String);
    procedure wwDBGrid1CalcTitleImage(Sender: TObject; Field: TField;
      var TitleImageAttributes: TwwTitleImageAttributes);
  private
    { Private declarations }
  public
    { Public declarations }
   aranan:string[50];
    siras:string[20];
    bk:string[10];
  end;

var
  Pardeglis: TPardeglis;

implementation

uses data, stokaral;

{$R *.DFM}


Function Buyut(str:string):string;
  var
  a,s:string;
  p,i:byte;
  begin
   s:=str;
   for i:=1 to length(str) do
   begin
     p:=pos(str[i],KucukHarf);
     if p>0 then
     begin
       a:=copy(buyukharf,p,1);
       s[i]:=a[1];
     end
     else s[i]:=str[i];
   end;
   Result:=s;
  end;
procedure TPardeglis.wwDBGrid1DblClick(Sender: TObject);
begin
  bTamamClick(sender);
end;

procedure TPardeglis.bTamamClick(Sender: TObject);
begin
modalresult:=mrOk;
end;

procedure TPardeglis.bVazgecClick(Sender: TObject);
begin
modalresult:=mrCancel;
end;

procedure TPardeglis.wwDBGrid1RowChanged(Sender: TObject);
begin
caption:='Stok Listesi   ( '+inttostr(dm.stokara.recno)+' / '+inttostr(dm.stokara.recordcount)+' )'
end;

procedure TPardeglis.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
dm.stokara.close;
pardeglis:=nil;
end;

procedure TPardeglis.FormCreate(Sender: TObject);
begin
dm.stokara.Close;
dm.stokara.SQL.Clear;
dm.stokara.SQL.Add('select * from stok');
dm.stokara.Open;
siras:='stokkodu';
bk:=' ASC';
aranan:='';
//dm.parcaliste.Sort := siras+bk;

  end;

procedure TPardeglis.FormKeyPress(Sender: TObject; var Key: Char);
var
l:byte;
KNO:INTEGER;
begin
  if key=#27 then
  begin
    key:=#0;
    bVazgecClick(sender);
  end else
  if key=#13 then
  begin
    key:=#0;
    bTamamClick(sender);
  end else
   if (ord(key)>31) or (key=#8)then
  begin
  if key=#8 then  delete(aranan,length(aranan),1)
  else aranan:=aranan+key;
  st.Caption:=' '+aranan;
  l:=length(aranan);
  dm.parcaliste.DisableControls;
  //  stok.stoktable.DisableControls;
  kno:=dm.parcaliste.RecNo;
  //kno:=stok.stoktable.recno;
  dm.parcaliste.First;
  //  stok.stoktable.First;
  while not dm.parcaliste.EOF do
  begin
    if Buyut(copy(dm.parcaliste.fields.FieldByName(siras).asstring,1,l))=Buyut(aranan) then break;
    dm.parcaliste.Next;
  end;
  if dm.parcaliste.EOF and( Buyut(copy(dm.parcaliste.fields.FieldByName(siras).asstring,1,l))<>Buyut(aranan)) then
    dm.parcaliste.recno:=kno;
    dm.parcaliste.EnableControls;
  end;
end;

procedure TPardeglis.wwDBGrid1CalcTitleAttributes(Sender: TObject;
  AFieldName: String; AFont: TFont; ABrush: TBrush;
  var ATitleAlignment: TAlignment);
begin
if siras=AFieldName then AFont.Style:=[fsBold] else AFont.Style:=[];
end;

procedure TPardeglis.wwDBGrid1TitleButtonClick(Sender: TObject;
  AFieldName: String);
begin
if AFieldName=siras then
  begin
    if bk=' ASC' then bk:=' DESC' else bk:=' ASC';
    end else bk:=' ASC';
    siras:=AFieldName;
    aranan:='';
    st.Caption:=' '+aranan;
    dm.stokara.Sort := siras+bk;
    wwDBGrid1.RedrawGrid;

    end;

procedure TPardeglis.wwDBGrid1CalcTitleImage(Sender: TObject;
  Field: TField; var TitleImageAttributes: TwwTitleImageAttributes);
begin
 if field.FieldName=siras then
  begin
    if bk=' ASC' then TitleImageAttributes.imageIndex:=0
    else TitleImageAttributes.imageIndex:=1;
  end
  else TitleImageAttributes.imageIndex:=-1;
end;

end.
